package com.lw.lwte.common.util;

import com.lw.lwte.common.enums.OsType;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class OsInfo {
    static final String OS = System.getProperty("os.name").toLowerCase();
    static OsInfo _instance = new OsInfo();
    OsType osType;

    OsInfo() {
    }

    public static boolean isLinux() {
        return OS.contains("linux");
    }

    public static boolean isMacOS() {
        return OS.contains("mac");
    }

    public static boolean isWindows() {
        return OS.contains("windows");
    }

    public static OsType getOsType() {
        if (isLinux()) {
            _instance.osType = OsType.Linux;
        } else if (isWindows()) {
            _instance.osType = OsType.Windows;
        } else if (isMacOS()) {
            _instance.osType = OsType.MacOS;
        } else {
            log.info("OS name: {}", OS);
            _instance.osType = OsType.Others;
        }

        return _instance.osType;
    }

    public static String getOsName(){
        return OS;
    }
}
